#include <bits/stdc++.h>
// 2025/01/20
// tag:
// Author: Zhang Muen
using namespace std;

const int MAX_NODES = 500010;
int nextNode[MAX_NODES][26]; // Array to store child nodes
int cntNodes[MAX_NODES];     // Array to store count of end-of-word markers
int nodeCount = 1;           // Start from 1 since 0 is the root
bool markVal[MAX_NODES];

int n, cnt, cnt2;
char ans[MAX_NODES * 3];

void dfs(int node)
{
    if (cntNodes[node])
    {
        ans[cnt++] = 'P';
        cnt2++;
    }
    if (cnt2 == n)
    {
        cout << cnt << endl;
        for (int i = 0; i < cnt; i++)
            cout << ans[i] << endl;
        return;
    }
    for (int i = 0; i < 26; i++)
    {
        if (nextNode[node][i] && !markVal[nextNode[node][i]])
        {
            ans[cnt++] = 'a' + i;
            dfs(nextNode[node][i]);
            ans[cnt++] = '-';
        }
    }
    for (int i = 0; i < 26; i++)
    {
        if (nextNode[node][i] && markVal[nextNode[node][i]])
        {
            ans[cnt++] = 'a' + i;
            dfs(nextNode[node][i]);
            ans[cnt++] = '-';
        }
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s, longests;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        int currentNode = 0;
        for (char c : s)
        {
            int index = c - 'a';
            if (!nextNode[currentNode][index])
                nextNode[currentNode][index] = nodeCount++;
            currentNode = nextNode[currentNode][index];
        }
        cntNodes[currentNode]++;
        if (s.size() > longests.size())
            longests = s;
    }

    int currentNode = 0;
    for (char c : longests)
        markVal[nextNode[currentNode][c - 'a']] = true, currentNode = nextNode[currentNode][c - 'a'];

    dfs(0);
    return 0;
}